package com.example.demo.service.impl;

import com.example.demo.constant.HeadEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author MarioZzz
 * @create 2023-09-25 18:55
 */
@Service
@Slf4j
public class CallTaskServerService {
    @Resource
    private RestTemplate restTemplate;

    public ResponseEntity<Map> getRefreshHttpResponse(Object... uriVariables) {
        String userName  = "admin";
        String password = "123";
        String url = "http://localhost:9092/flow-cloud-dtask/remoteTaskList/token";

        HttpHeaders headers = new HttpHeaders();
        headers.set(HeadEnum.USER_NAME.value, userName);
        headers.set(HeadEnum.PASSWORD.value, password);
        headers.set(HeadEnum.DO_REFRESH.value, "doRefresh");

        log.info("开始刷新调度平台token");
        log.info("用户名=={},密码==={}",userName,password);
        log.info("调度平台地址{}",url);

        HttpEntity<?> requestEntity = new HttpEntity<>(null, headers);

        ResponseEntity<Map> responseEntity =
                restTemplate.exchange(url, HttpMethod.GET, requestEntity, Map.class);

        return responseEntity;
    }

}
